Passed
Push — master ( d9e5dd...36764d )
by Spuds
01:07 queued 26s
created

profile.js ➔ previewUploadedAvatar   A

Complexity

Conditions 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 12
dl 0
loc 19
rs 9.8
c 0
b 0
f 0
1
/*!
2
 * @name      ElkArte Forum
3
 * @copyright ElkArte Forum contributors
4
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
5
 *
6
 * This file contains code covered by:
7
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
8
 * license:		BSD, See included LICENSE.TXT for terms and conditions.
9
 *
10
 * @version 1.1.9
11
 */
12
13
/**
14
 * This file contains javascript associated with the user profile
15
 */
16
17
$(function() {
18
	// Profile options changing karma
19
	$('#karma_good, #karma_bad').keyup(function() {
20
		var good = parseInt($('#karma_good').val()),
21
			bad = parseInt($('#karma_bad').val());
22
23
		$('#karmaTotal').text((isNaN(good) ? 0 : good) - (isNaN(bad) ? 0 : bad));
24
	});
25
	$('.toggle_notify').change(function() {
26
		if (this.checked)
27
			$('#' + this.id + '_method').fadeIn('fast');
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
28
		else
29
			$('#' + this.id + '_method').fadeOut('fast');
30
	}).change();
31
});
32
33
/**
34
 * Profile tabs (summary, recent, buddy), for use with jqueryUI
35
 */
36
function start_tabs() {
37
	$("#tabs").tabs({
38
		// Called before tab content is loaded with href
39
		beforeLoad: function (event, ui) {
40
			// The ubiquitous ajax spinner
41
			ui.panel.html('<div class="centertext"><i class="icon icon-spin icon-big i-spinner"></i></div>');
42
43
			// Ajax call failed to retrieve content
44
			ui.jqXHR.fail(function () {
45
				ui.panel.html('<div></div>');
46
				if ('console' in window) {
47
					window.console.info(event);
48
					window.console.info(ui);
49
				}
50
			});
51
		}
52
	});
53
}
54
55
/**
56
 * Function to detect the time offset and populate the offset box
57
 *
58
 * @param {string} currentTime
59
 */
60
var localTime = new Date();
61
function autoDetectTimeOffset(currentTime)
62
{
63
	var serverTime;
64
65
	if (typeof(currentTime) !== 'string')
66
		serverTime = currentTime;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
67
	else
68
		serverTime = new Date(currentTime);
69
70
	// Something wrong?
71
	if (!localTime.getTime() || !serverTime.getTime())
72
		return 0;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
73
74
	// Get the difference between the two, set it up so that the sign will tell us who is ahead of who.
75
	var diff = Math.round((localTime.getTime() - serverTime.getTime())/3600000);
76
77
	// Make sure we are limiting this to one day's difference.
78
	diff %= 24;
79
80
	return diff;
81
}
82
83
/**
84
 * Calculates the number of available characters remaining when filling in the
85
 * signature box
86
 */
87
var oldSignature = "";
88
function calcCharLeft(init)
89
{
90
	var currentSignature = document.forms.creator.signature.value,
91
		currentChars = 0;
92
93
	if (!document.getElementById("signatureLeft"))
94
		return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
95
96
	init = typeof init !== 'undefined' ? init : false;
97
98
	if (oldSignature !== currentSignature)
99
	{
100
		oldSignature = currentSignature;
101
102
		currentChars = currentSignature.replace(/\r/, "").length;
103
		if (is_opera)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable is_opera is declared in the current environment, consider using typeof is_opera === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
104
			currentChars = currentSignature.replace(/\r/g, "").length;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
105
106
		if (currentChars > maxLength)
0 ignored issues
show
Bug introduced by
The variable maxLength seems to be never declared. If this is a global, consider adding a /** global: maxLength */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
107
			document.getElementById("signatureLeft").className = "error";
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
108
		else
109
			document.getElementById("signatureLeft").className = "";
110
111
		var $_profile_error = $("#profile_error");
112
		if (currentChars > maxLength && !$_profile_error.is(":visible"))
113
			ajax_getSignaturePreview(false);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
114
		else if (currentChars <= maxLength && $_profile_error.is(":visible") && !init)
115
		{
116
			$_profile_error.css({display:"none"});
117
			$_profile_error.html('');
118
		}
119
	}
120
121
	document.getElementById("signatureLeft").innerHTML = maxLength - currentChars;
122
}
123
124
/**
125
 * Gets the signature preview via ajax and populates the preview box
126
 *
127
 * @param {boolean} showPreview
128
 */
129
function ajax_getSignaturePreview(showPreview)
130
{
131
	showPreview = (typeof showPreview === 'undefined') ? false : showPreview;
132
	$.ajax({
133
		type: "POST",
134
		url: elk_scripturl + "?action=xmlpreview;xml",
0 ignored issues
show
Bug introduced by
The variable elk_scripturl seems to be never declared. If this is a global, consider adding a /** global: elk_scripturl */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
135
		data: {item: "sig_preview", signature: $("#signature").val(), user: $('input[name="u"]').attr("value")},
136
		context: document.body
137
	})
138
	.done(function(request) {
139
		var i = 0;
140
141
		if (showPreview)
142
		{
143
			var signatures = ["current", "preview"];
144
			for (i = 0; i < signatures.length; i++)
145
			{
146
				$("#" + signatures[i] + "_signature").css({display:"block"});
147
				$("#" + signatures[i] + "_signature_display").css({display:"block"}).html($(request).find('[type="' + signatures[i] + '"]').text() + '<hr />');
148
			}
149
150
			$('.spoilerheader').on('click', function(){
151
				$(this).next().children().slideToggle("fast");
152
			});
153
		}
154
155
		var $_profile_error = $("#profile_error");
156
157
		if ($(request).find("error").text() !== '')
158
		{
159
			if (!$_profile_error.is(":visible"))
160
				$_profile_error.css({display: "", position: "fixed", top: 0, left: 0, width: "100%", 'z-index': '100'});
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
161
162
			var errors = $(request).find('[type="error"]'),
163
				errors_html = '<span>' + $(request).find('[type="errors_occurred"]').text() + '</span><ul>';
164
165
			for (i = 0; i < errors.length; i++)
166
				errors_html += '<li>' + $(errors).text() + '</li>';
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
167
168
			errors_html += '</ul>';
169
			$(document).find("#profile_error").html(errors_html);
170
		}
171
		else
172
		{
173
			$_profile_error.css({display:"none"});
174
			$_profile_error.html('');
175
		}
176
177
		return false;
178
	});
179
180
	return false;
181
}
182
183
/**
184
 * Allows previewing of server stored avatars stored.
185
 *
186
 * @param {type} selected
187
 */
188
function changeSel(selected)
189
{
190
	if (cat.selectedIndex === -1)
0 ignored issues
show
Bug introduced by
The variable cat seems to be never declared. If this is a global, consider adding a /** global: cat */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
191
		return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
192
193
	if (cat.options[cat.selectedIndex].value.indexOf("/") > 0)
194
	{
195
		var i,
196
			count = 0;
197
198
		file.style.display = "inline";
0 ignored issues
show
Bug introduced by
The variable file seems to be never declared. If this is a global, consider adding a /** global: file */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
199
		file.disabled = false;
200
201
		for (i = file.length; i >= 0; i -= 1)
202
			file.options[i] = null;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
203
204
		for (i = 0; i < files.length; i++)
0 ignored issues
show
Bug introduced by
The variable files seems to be never declared. If this is a global, consider adding a /** global: files */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
205
			if (files[i].indexOf(cat.options[cat.selectedIndex].value) === 0)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
206
			{
207
				var filename = files[i].substr(files[i].indexOf("/") + 1);
208
				var showFilename = filename.substr(0, filename.lastIndexOf("."));
209
				showFilename = showFilename.replace(/[_]/g, " ");
210
211
				file.options[count] = new Option(showFilename, files[i]);
0 ignored issues
show
Bug introduced by
The variable Option seems to be never declared. If this is a global, consider adding a /** global: Option */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
212
213
				if (filename === selected)
214
				{
215
					if (file.options.defaultSelected)
216
						file.options[count].defaultSelected = true;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
217
					else
218
						file.options[count].selected = true;
219
				}
220
221
				count++;
222
			}
223
224
		if (file.selectedIndex === -1 && file.options[0])
225
			file.options[0].selected = true;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
226
227
		showAvatar();
228
	}
229
	else
230
	{
231
		file.style.display = "none";
232
		file.disabled = true;
233
		document.getElementById("avatar").src = avatardir + cat.options[cat.selectedIndex].value;
0 ignored issues
show
Bug introduced by
The variable avatardir seems to be never declared. If this is a global, consider adding a /** global: avatardir */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
234
		document.getElementById("avatar").style.width = "";
235
		document.getElementById("avatar").style.height = "";
236
	}
237
}
238
239
function init_avatars()
240
{
241
	var avatar = document.getElementById("avatar");
242
243
	// If we are using an avatar from the gallery, let's load it
244
	if (avatar !== null)
245
		changeSel(selavatar);
0 ignored issues
show
Bug introduced by
The variable selavatar seems to be never declared. If this is a global, consider adding a /** global: selavatar */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
246
247
	// And now show the proper interface for the selected avatar type
248
	swap_avatar();
249
}
250
251
// Show the right avatar based on what radio button they just selected
252
function swap_avatar()
253
{
254
	$('#avatar_choices').find('input').each(function() {
255
		var choice_id = $(this).attr('id');
256
257
		if ($(this).is(':checked'))
258
			$('#' + choice_id.replace('_choice', '')).css({display: 'block'});
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
259
		else
260
			$('#' + choice_id.replace('_choice', '')).css({display: 'none'});
261
	});
262
263
	return true;
264
}
265
266
/**
267
 * Updates the avatar img preview with the selected one
268
 */
269
function showAvatar()
270
{
271
	if (file.selectedIndex === -1)
0 ignored issues
show
Bug introduced by
The variable file seems to be never declared. If this is a global, consider adding a /** global: file */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
272
		return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
273
274
	var oAvatar = document.getElementById("avatar");
275
276
	oAvatar.src = avatardir + file.options[file.selectedIndex].value;
0 ignored issues
show
Bug introduced by
The variable avatardir seems to be never declared. If this is a global, consider adding a /** global: avatardir */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
277
	oAvatar.alt = file.options[file.selectedIndex].text;
278
	oAvatar.style.width = "";
279
	oAvatar.style.height = "";
280
}
281
282
/**
283
 * Allows for the previewing of an externally stored avatar
284
 *
285
 * @param {string} src
286
 */
287
function previewExternalAvatar(src)
288
{
289
	var oSid = document.getElementById("external");
290
291
	// Assign the source to the image tag
292
	oSid.src = src;
293
294
	// Create an in-memory element to measure the real size of the image
295
	$('<img />').on('load', function() {
296
		if (refuse_too_large && ((maxWidth !== 0 && this.width > maxWidth) || (maxHeight !== 0 && this.height > maxHeight)))
0 ignored issues
show
Bug introduced by
The variable maxHeight seems to be never declared. If this is a global, consider adding a /** global: maxHeight */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable maxWidth seems to be never declared. If this is a global, consider adding a /** global: maxWidth */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Best Practice introduced by
If you intend to check if the variable refuse_too_large is declared in the current environment, consider using typeof refuse_too_large === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
297
			$('#avatar_external').addClass('error');
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
298
		else
299
			$('#avatar_external').removeClass('error');
300
	}).attr('src', src);
301
}
302
303
/**
304
 * Allows for the previewing of an uploaded avatar
305
 *
306
 * @param {object} src
307
 */
308
function previewUploadedAvatar(src)
309
{
310
	if (src.files && src.files[0])
311
	{
312
		let reader = new FileReader();
0 ignored issues
show
Bug introduced by
The variable FileReader seems to be never declared. If this is a global, consider adding a /** global: FileReader */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
313
314
		reader.readAsDataURL(src.files[0]);
315
		reader.onload = function ()
316
		{
317
			let current_avatar = document.getElementById('current_avatar'),
318
				current_avatar_new = document.getElementById('current_avatar_new'),
319
				current_avatar_new_preview = document.getElementById('current_avatar_new_preview');
320
321
			current_avatar_new_preview.src = String(reader.result);
322
			current_avatar_new.classList.remove('hide');
323
			current_avatar.classList.add('hide');
324
		};
325
	}
326
}
327
328
/**
329
 * Disable notification boxes as required.  This is in response to selecting the
330
 * notify user checkbox in the issue a warning screen
331
 */
332
function modifyWarnNotify()
333
{
334
	var disable = !document.getElementById('warn_notify').checked;
335
336
	document.getElementById('warn_sub').disabled = disable;
337
	document.getElementById('warn_body').disabled = disable;
338
	document.getElementById('warn_temp').disabled = disable;
339
	document.getElementById('new_template_link').style.display = disable ? 'none' : 'inline-block';
340
	document.getElementById('preview_button').style.display = disable ? 'none' : 'inline-block';
341
342
	$("#preview_button").on('click', function() {
343
		$.ajax({
344
			type: "POST",
345
			url: elk_scripturl + "?action=xmlpreview;xml",
0 ignored issues
show
Bug introduced by
The variable elk_scripturl seems to be never declared. If this is a global, consider adding a /** global: elk_scripturl */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
346
			data: {
347
				item: "warning_preview",
348
				title: $("#warn_sub").val(),
349
				body: $("#warn_body").val(),
350
				issuing: true
351
			},
352
			context: document.body
353
		})
354
		.done(function(request) {
355
			var $_preview = $("#box_preview"),
356
				$_profile_error = $("#profile_error");
357
358
			$_preview.show();
359
			$_preview.html($(request).find('body').text());
360
361
			if ($(request).find("error").text() !== '')
362
			{
363
				$_profile_error.show();
364
				var errors_html = '<span>' + $_profile_error.find("span").html() + '</span>' + '<ul class="list_errors">';
365
366
				$(request).find('error').each(function() {
367
					errors_html += '<li>' + $(this).text() + '</li>';
368
				});
369
				errors_html += '</ul>';
370
				$_profile_error.html(errors_html);
371
				$('html, body').animate({ scrollTop: $_profile_error.offset().top }, 'slow');
372
			}
373
			else
374
			{
375
				$_profile_error.hide();
376
				$("#error_list").html('');
377
				$('html, body').animate({ scrollTop: $("#box_preview").offset().top }, 'slow');
378
			}
379
380
			return false;
381
		});
382
383
		return false;
384
	});
385
}
386
387
/**
388
 * onclick function, triggered in response to selecting + or - in the warning screen
389
 * Increases the warning level by a defined amount
390
 *
391
 * @param {string} sliderID
392
 * @param {string} levelID
393
 * @param {int[]} levels
394
 */
395
function initWarnSlider(sliderID, levelID, levels)
396
{
397
	var $_levelID = $("#" + levelID),
398
		$_sliderID = $("#" + sliderID);
399
400
	$_sliderID.slider({
401
		range: "min",
402
		min: 0,
403
		max: 100,
404
		slide: function(event, ui) {
405
			$_levelID .val(ui.value);
406
407
			$(this).removeClass("watched moderated muted");
408
409
			if (ui.value >= levels[3])
410
				$(this).addClass("muted");
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
411
			else if (ui.value >= levels[2])
412
				$(this).addClass("moderated");
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
413
			else if (ui.value >= levels[1])
414
				$(this).addClass("watched");
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
415
		},
416
		change: function(event, ui) {
417
			$_levelID .val(ui.value);
418
419
			$(this).removeClass("watched moderated muted");
420
421
			if (ui.value >= levels[3])
422
				$(this).addClass("muted");
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
423
			else if (ui.value >= levels[2])
424
				$(this).addClass("moderated");
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
425
			else if (ui.value >= levels[1])
426
				$(this).addClass("watched");
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
427
		}
428
	}).slider("value", $_levelID .val());
429
430
	// Just in case someone wants to type, let's keep the two in synch
431
	$_levelID .keyup(function() {
432
		var val = Math.max(0, Math.min(100, $(this).val()));
433
434
		$_sliderID.slider("value", val);
435
	});
436
}
437
438
/**
439
 * Fills the warning template box based on the one chosen by the user
440
 */
441
function populateNotifyTemplate()
442
{
443
	var index = document.getElementById('warn_temp').value;
444
445
	// No selection means no template
446
	if (index === -1)
447
		return false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
448
449
	// Otherwise see what we can do...
450
	for (var key in templates)
0 ignored issues
show
Bug introduced by
The variable templates seems to be never declared. If this is a global, consider adding a /** global: templates */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
451
	{
452
		// Found the template, load it and stop
453
		if (index === key)
454
		{
455
			document.getElementById('warn_body').value = templates[key];
456
			break;
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
457
		}
458
	}
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
459
}
460